package com.sinovatech.ologger.actionlog.service;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.sinovatech.ologger.actionlog.core.OperationLogPersistence;
import com.sinovatech.ologger.actionlog.dao.OperationLogDao;
import com.sinovatech.ologger.actionlog.entity.OperationLog;
import com.sinovatech.ologger.actionlog.vo.OperationLogVO;
import com.sinovatech.ologger.core.dao.support.Page;

public class ActionLogService implements OperationLogPersistence{

	@SuppressWarnings("unused")
	private static final Log logger = LogFactory.getLog(ActionLogService.class);

	private OperationLogDao operationLogDao;
	
	@SuppressWarnings("unchecked")
	public Page findOperationLogPageByCondition(OperationLogVO logVO) {
		Page page = this.operationLogDao.findOperationLogPageByCondition(logVO);
		if(page != null && !CollectionUtils.isEmpty((Collection<?>) page.getResult())){
			List<OperationLog> result = (List<OperationLog>) page.getResult();
			List<OperationLogVO> resultTmp = new ArrayList<OperationLogVO>();
			for (OperationLog operationLog : result) {
				OperationLogVO olVO = new OperationLogVO(operationLog);
				resultTmp.add(olVO);
			}
			page.setResult(resultTmp);
		}
		return page;
	}
	
	public void saveOperationLog(OperationLog log){
		this.operationLogDao.save(log);
	}

	public void setOperationLogDao(OperationLogDao operationLogDao) {
		this.operationLogDao = operationLogDao;
	}
}
